/*******************************************************************************
 * Copyright (c) 2011 Erik Byström.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package se.slackers.automatunes.ui;

import javax.swing.JComponent;

/**
 * @author Erik Byström
 * 
 */
public abstract class BaseParameter<T, F extends JComponent> implements Parameter<T, F> {
	protected final String name;
	protected String tooltip;

	public BaseParameter(final String name) {
		this.name = name;
	}

	@Override
	public int compareTo(final Parameter<?, ?> o) {
		return name.compareTo(o.name());
	}

	@Override
	public final Parameter<T, F> tooltip(final String tooltip) {
		this.tooltip = tooltip;
		return this;
	}

	@Override
	public final String tooltip() {
		if (tooltip == null) {
			return "";
		}
		return tooltip;
	}

	@Override
	public final String name() {
		return name;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final Parameter<?, ?> other = (Parameter<?, ?>) obj;
		if (name == null) {
			if (other.name() != null) {
				return false;
			}
		} else if (!name.equals(other.name())) {
			return false;
		}
		return true;
	}
}
